package leetcode.Y2024M6.review;

import org.junit.Test;

public class S45 {
    public int jump(int[] nums) {
        int step = 0;
        int maxPosition = 0;
        int border = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            maxPosition = Math.max(maxPosition, nums[i] + i);
            if (i == border) {
                border = maxPosition;
                step++;
            }
        }
        return step;
    }

    @Test
    public void test() {
        int[] arr={2,3,1,1,4};
        System.out.println(jump(arr));
    }
}
